<?php

namespace kb;

use PhpWebView\WebView;
use PhpWebView\WindowSizeHint;

class App
{
    // 版本
    const VERSION = '0.0.1';
    // webview
    private $WEBVIEW = null;
    // 应用目录
    protected $APP_PATH = 'app' . DIRECTORY_SEPARATOR;

    public function __construct()
    {
        if ($this->WEBVIEW === null) {
            // 初始化
            $windows = require_once APP_PATH . '/config/windows.php';
            $app = require_once APP_PATH . '/config/app.php';
            $this->WEBVIEW = new WebView(
                title: $windows['title'],
                width: $windows['width'],
                height: $windows['height'],
                hint: WindowSizeHint::from($windows['hint']),
                debug: $app['debug']
            );
        }
    }

    public function getView()
    {
        return $this->WEBVIEW;
    }

    public function jump()
    {
        $this->WEBVIEW->bind(
            name: "jump",
            function: function ($seq, $req, $context) {

            }
        );
    }


    public function run()
    {
        $this->WEBVIEW->run()->destroy();
    }
}
